home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / PEAR / Frontend.php < prev    next >
Encoding:
PHP Script  |  2005-12-02  |  4.5 KB  |  142 lines

  1. <?php
  2. /**
  3.  * PEAR_Frontend, the singleton-based frontend for user input/output
  4.  *
  5.  * PHP versions 4 and 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   pear
  14.  * @package    PEAR
  15.  * @author     Greg Beaver <cellog@php.net>
  16.  * @copyright  1997-2005 The PHP Group
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: Frontend.php,v 1.4 2005/04/13 04:17:45 cellog Exp $
  19.  * @link       http://pear.php.net/package/PEAR
  20.  * @since      File available since Release 1.4.0a1
  21.  */
  22.  
  23. /**
  24.  * Which user interface class is being used.
  25.  * @var string class name
  26.  */
  27. $GLOBALS['_PEAR_FRONTEND_CLASS'] = 'PEAR_Frontend_CLI';
  28.  
  29. /**
  30.  * Instance of $_PEAR_Command_uiclass.
  31.  * @var object
  32.  */
  33. $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = null;
  34.  
  35. /**
  36.  * Singleton-based frontend for PEAR user input/output
  37.  * @category   pear
  38.  * @package    PEAR
  39.  * @author     Greg Beaver <cellog@php.net>
  40.  * @copyright  1997-2005 The PHP Group
  41.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  42.  * @version    Release: 1.4.5
  43.  * @link       http://pear.php.net/package/PEAR
  44.  * @since      Class available since Release 1.4.0a1
  45.  */
  46. class PEAR_Frontend extends PEAR
  47. {
  48.     /**
  49.      * Retrieve the frontend object
  50.      * @return PEAR_Frontend_CLI|PEAR_Frontend_Web|PEAR_Frontend_Gtk
  51.      * @static
  52.      */
  53.     function &singleton($type = null)
  54.     {
  55.         if ($type === null) {
  56.             if (!isset($GLOBALS['_PEAR_FRONTEND_SINGLETON'])) {
  57.                 $a = false;
  58.                 return $a;
  59.             }
  60.             return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
  61.         } else {
  62.             $a = PEAR_Frontend::setFrontendClass($type);
  63.             return $a;
  64.         }
  65.     }
  66.  
  67.     function &setFrontendClass($uiclass)
  68.     {
  69.         if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
  70.               is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) {
  71.             return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
  72.         }
  73.         if (!class_exists($uiclass)) {
  74.             $file = str_replace('_', '/', $uiclass) . '.php';
  75.             if (PEAR_Frontend::isIncludeable($file)) {
  76.                 include_once $file;
  77.             }
  78.         }
  79.         if (class_exists($uiclass)) {
  80.             $obj = &new $uiclass;
  81.             // quick test to see if this class implements a few of the most
  82.             // important frontend methods
  83.             if (method_exists($obj, 'userConfirm')) {
  84.                 $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$obj;
  85.                 $GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass;
  86.                 return $obj;
  87.             } else {
  88.                 $err = PEAR::raiseError("not a frontend class: $uiclass");
  89.                 return $err;
  90.             }
  91.         }
  92.         $err = PEAR::raiseError("no such class: $uiclass");
  93.         return $err;
  94.     }
  95.  
  96.     /**
  97.      * @param string $path relative or absolute include path
  98.      * @return boolean
  99.      * @static
  100.      */
  101.     function isIncludeable($path)
  102.     {
  103.         if (file_exists($path) && is_readable($path)) {
  104.             return true;
  105.         }
  106.         $ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
  107.         foreach ($ipath as $include) {
  108.             $test = realpath($include . DIRECTORY_SEPARATOR . $path);
  109.             if (!$test) { // support wrappers like phar (realpath just don't work with them)
  110.                 $test = $include . DIRECTORY_SEPARATOR . $path;
  111.             }
  112.             if (file_exists($test) && is_readable($test)) {
  113.                 return true;
  114.             }
  115.         }
  116.         return false;
  117.     }
  118.  
  119.     /**
  120.      * @param PEAR_Config
  121.      */
  122.     function setConfig(&$config)
  123.     {
  124.     }
  125.  
  126.     /**
  127.      * This can be overridden to allow session-based temporary file management
  128.      *
  129.      * By default, all files are deleted at the end of a session.  The web installer
  130.      * needs to be able to sustain a list over many sessions in order to support
  131.      * user interaction with install scripts
  132.      */
  133.     function addTempFile($file)
  134.     {
  135.         $GLOBALS['_PEAR_Common_tempfiles'][] = $file;
  136.     }
  137.  
  138.     function log($level, $msg, $append_crlf = true)
  139.     {
  140.     }
  141. }
  142. ?>